package midterm.demo2;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test2 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        String userStrs = "10001:张三:男:1990-01-01#10002:李四:女:1989-01-09#10003:王五:男:1999-09-09" +
                "#10004:刘备:男:1899-01-01#10005:孙悟空:男:1900-01-01#10006:张三:女:1999-01-01" +
                "#10007:刘备:女:1999-01-01#10008:张三:女:2003-07-01#10009:猪八戒:男:1900-01-01";
        String regex = "\\d{5}:.{2,3}:.:\\d{4}-\\d{2}-\\d{2}";
        Pattern pattern = Pattern.compile(regex);
        //通过pattern对象得到查找内容的匹配器
        Matcher matcher = pattern.matcher(userStrs);

        while(matcher.find()){
            String[] str = matcher.group().split(":");
            String name = str[1];
            if (map.containsKey(name)){
                map.put(name, map.get(name) + 1);
            }
            else {
                map.put(name, 1);
            }

        }
        System.out.println(map);
    }
}
